package com.koron.operation.classes.form.service.impl;


import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.koron.operation.classes.form.bean.po.ClassesFormShift;
import com.koron.operation.classes.form.bean.query.ClassesFormShiftQuery;
import com.koron.operation.classes.form.mapper.ClassesFormShiftMapper;
import com.koron.operation.classes.form.service.ClassesFormShiftService;
import lombok.RequiredArgsConstructor;
import org.koron.ebs.mybatis.SessionFactory;
import org.koron.ebs.mybatis.TaskAnnotation;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 月度排班班次(ClassesFormShift)表服务实现类
 *
 * @author jzp
 * @since 2023-05-17 09:43:30
 */
@Service
@RequiredArgsConstructor
public class ClassesFormShiftServiceImpl implements ClassesFormShiftService {

    /**
     * 通过ID查询单条数据
     */
    @Override
    @TaskAnnotation("getById")
    public ClassesFormShift getById(SessionFactory factory, String id) {
        ClassesFormShiftMapper mapper = factory.getMapper(ClassesFormShiftMapper.class);
        return mapper.selectById(id);
    }

    /**
     * 查询所有数据
     */
    @Override
    @TaskAnnotation("list")
    public List<ClassesFormShift> list(SessionFactory factory, ClassesFormShiftQuery query) {
        ClassesFormShiftMapper mapper = factory.getMapper(ClassesFormShiftMapper.class);
        return mapper.selectList(query);
    }

    /**
     * 新增数据
     */
    @Override
    @TaskAnnotation("save")
    public boolean save(SessionFactory factory, ClassesFormShift classesFormShift) {
        ClassesFormShiftMapper mapper = factory.getMapper(ClassesFormShiftMapper.class);
        return mapper.insertOrUpdate(classesFormShift) > 0;
    }

    @Override
    @TaskAnnotation("saveBatch")
    public boolean saveBatch(SessionFactory factory, List<ClassesFormShift> shiftList) {
        if (CollUtil.isEmpty(shiftList)) {
            return false;
        }
        ClassesFormShiftMapper mapper = factory.getMapper(ClassesFormShiftMapper.class);
        return mapper.insertOrUpdateBatch(shiftList) > 0;
    }

    /**
     * 修改数据
     */
    @Override
    @TaskAnnotation("update")
    public boolean update(SessionFactory factory, ClassesFormShift classesFormShift) {
        ClassesFormShiftMapper mapper = factory.getMapper(ClassesFormShiftMapper.class);
        return mapper.update(classesFormShift) > 0;
    }

    @Override
    @TaskAnnotation("updateChangeStatus")
    public boolean updateChangeStatus(SessionFactory factory, String id, String changeStatus) {
        ClassesFormShift classesFormShift = new ClassesFormShift();
        classesFormShift.setId(id);
        classesFormShift.setChangeStatus(changeStatus);
        return update(factory, classesFormShift);
    }

    /**
     * 通过主键删除数据
     */
    @Override
    @TaskAnnotation("deleteById")
    public boolean deleteById(SessionFactory factory, String id) {
        ClassesFormShiftMapper mapper = factory.getMapper(ClassesFormShiftMapper.class);
        return mapper.hidden(id) > 0;
    }

    @Override
    @TaskAnnotation("removeByFormId")
    public boolean removeByFormId(SessionFactory factory, String formId) {
        if (StrUtil.isEmpty(formId)) {
            return false;
        }
        ClassesFormShiftMapper mapper = factory.getMapper(ClassesFormShiftMapper.class);
        return mapper.removeByFormId(formId) > 0;
    }

}
